#ifndef WIDGETFADE_H
#define WIDGETFADE_H

#include <QObject>
#include <QWidget>
#include <QList>
#include <QThread>
#include <QDebug>
#include <QPainter>
#include <QGraphicsOpacityEffect>

class WidgetFade : public QThread
{
    Q_OBJECT
public:
    /*
     *  Constructor of the object
     *  @param QList<QWidget *> widgetList : List of the widget to fade
     */
    explicit WidgetFade(QList<QWidget *> widgetList = QList<QWidget*>(), QObject *parent = 0);

    /*
     *  Constructor of the object
     *  @param QWidget * widget : Widget to fade
     */
    WidgetFade(QWidget * widget, QObject *parent = 0);
    ~WidgetFade();


    /*
     *  Function to set the speed of the annimation (The more the value is high, the slower will be the animation)
     *  @param float speed : Speed of the animation
     */
    void setSpeed(float speed = 10);

    /*
     *  Function to start the fading
     *  @param float currentOpacity : Current opacity where to start the fading
     *  @param float newOpacity : The opacity where to fade the objects
     *  @param float speed : The speed of the animation
     */
    void fade(float currentOpacity = 1.0, float newOpacity = 1.0 ,float speed = 10);

    /*
     *  Function to reset the widgets list
     */
    void clearWidgetList();

    /*
     *  Function to set a new widgets list
     *  @param QList<QWidget*> widgetList : The new widgets list
     */
    void setWidgetList(QList<QWidget*> widgetList);

    /*
     *  Function get the average time of the animation based of the current animation speed (can be used for temporisation)
     *  @return int : Time in milliseconds of the animation
     */
    int getTime();

    /*
     *  Function to check if there is a current animation
     *  @return bool : Boolean if there is an animation
     */
    bool isFading();



    /*
     *  Function to stop the current fading
     */
    void stopFading();


private:
    /*
     *  Function to set the effect list based of the current widgets list
     */
    void setEffectList();

    /*
     *  Function called from the fade function to start the fading thread
     */
    void run();


    QList<QWidget*> * widgetList;                           //Pointer to the widget list
    float newOpacity;                                       //The new opacity to set to all object
    float currentOpacity;                                   //The current opacity of the objects
    int speed;                                              //The current speed of the animation
    QList<QGraphicsOpacityEffect *> * effectList;           //Pointer to a effect list
    bool actuallyFading;                                    //Boolean if there is an animation or not
signals:
    void signalChangeOpacity(qreal);
public slots:
};

#endif // WIDGETFADE_H
